package com.zlf.blog.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zlf.blog.dao.pojo.Tag;
import com.zlf.blog.service.TagsService;
import com.zlf.blog.dao.mapper.TagMapper;
import com.zlf.blog.vo.TagVo;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
* @author zlfi1
* @description 针对表【ms_tag】的数据库操作Service实现
* @createDate 2022-07-02 09:33:28
*/
@Service
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
public class TagsServiceImpl extends ServiceImpl<TagMapper, Tag>
implements TagsService {
    private final  TagMapper tagMapper;

    public TagVo copy(Tag tag){
        TagVo tagVo=new TagVo();
        BeanUtils.copyProperties(tag,tagVo);
        return tagVo;
    }
    public List<TagVo> copyList(List<Tag> tagList){
        List<TagVo> tagVoList=new ArrayList<>();
        for (Tag tag : tagList) {
            tagVoList.add(copy(tag));
        }
        return tagVoList;
    }
    @Override
    public List<TagVo> findTagsByArticleId(String articleId) {
        //mybatis-plus无法进行多表查询
        List<Tag> tags=tagMapper.findTagByArticleId(articleId);
        return copyList(tags);
    }
}
